package com.bowen.spike.controller;


import com.bowen.spike.common.Result;
import com.bowen.spike.entity.ProductType;
import com.bowen.spike.service.IProductTypeService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品类型表 前端控制器
 * </p>
 *
 * @author bowen
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/api/product-type")
@RequiredArgsConstructor
public class ProductTypeController {

    private final IProductTypeService productTypeService;

    @GetMapping
    public Result<List<ProductType>> getAllProductTypes() {
        List<ProductType> productTypes = productTypeService.getAllProductTypes();
        return Result.ok(productTypes);
    }

    @GetMapping("/{id}")
    public Result<ProductType> getProductTypeById(@PathVariable Long id) {
        ProductType productType = productTypeService.getProductTypeById(id);
        return Result.ok(productType);
    }

    @PostMapping
    public Result<Void> createProductType(@Valid @RequestBody ProductType productType) {
        productTypeService.createProductType(productType);
        return Result.ok();
    }

}
